<template>
	<view class="page" :style="themeColor">
		<view class="flex benben-position-layout flex flex-wrap align-center inputNewPhone_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub inputNewPhone_fd0_0'>
				<view class='flex flex-wrap align-center'>
					<person></person>
				</view>
				<view class='flex flex-wrap align-stretch justify-center flex-sub'>
					<text class='inputNewPhone_fd0_0_c1_c0'>绑定新手机</text>
				</view>
				<view class='flex flex-wrap align-center inputNewPhone_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

		<view class="flex flex-direction flex-wrap align-stretch inputNewPhone_flex_1">
			<view style="padding: 8rpx 0;">
				<back></back>
			</view>
			<view class='flex flex-wrap align-center inputNewPhone_fd1_0' @tap.stop="pickerDiy1678760201193=true">
				<text class='inputNewPhone_fd1_0_c0'>区号选择</text>
				<input class='flex-sub inputNewPhone_fd1_0_c1' type="text" placeholder="请选择区号" confirm-type="done"
					:maxlength="-1" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="area"
					disabled="true" />
			</view>
			<view class='flex flex-wrap align-center inputNewPhone_fd1_0'>
				<text class='inputNewPhone_fd1_0_c0'>新手机号码</text>
				<input class='flex-sub inputNewPhone_fd1_0_c1' type="number" :focus='true' placeholder="请输入新的手机号"
					confirm-type="done" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
					v-model="newPhone" />
			</view>
			<view class='flex flex-wrap align-center inputNewPhone_fd1_0'>
				<text class='inputNewPhone_fd1_0_c0'>短信验证</text>
				<input class='flex-sub inputNewPhone_fd1_1_c1' type="number" placeholder="请输入验证码" confirm-type="done"
					:maxlength="6" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
					v-model="smsVerification" />
				<benben-send-verification-code class='flex  inputNewPhone_fd1_1_c2' after-text='后重新获取'
					before-text='获取短信验证' :type='type' :phone="newPhone"
					:area_code="list"></benben-send-verification-code>
			</view>
			<button class='flex-sub inputNewPhone_fd1_2' @tap.stop="bindNewPhoneNumberFunc()">完成</button>
		</view>


		<benben-picker ref="benbenWritePickerCodepicker11" :visible.sync="pickerDiy1678760201193" :label.sync='area'
			:value.sync='list' :options='areaList' mode='selector' :mask-show='true' :timeout='true' :picker-height='88'
			default-type='prefix' :default-props='{"label":"country","value":"prefix"}'>
			<template #picker-header>
				<view class='flex flex-wrap align-center justify-between MyInformation_picker5_0'>
					<text @tap="$refs.benbenWritePickerCodepicker11.cancel()">取消</text>
					<text>区号</text>
					<text class='MyInformation_picker5_0_c2'
						@tap="$refs.benbenWritePickerCodepicker11.pickerConfirm()">确认</text>
				</view>
			</template>
		</benben-picker>

	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	import back from "@/components/back/index.vue"
	import person from "@/components/person/index.vue"
	export default {
		components: {
			back,
			person
		},


		data() {
			return {
				"newPhone": "",
				"smsVerification": "",
				"phone": "",
				list: '',
				type: 7,
				areaList: [],
				"pickerDiy1678760201193": false,
				area_code: '',
				area: '',
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {
				phone
			} = options
			if (phone !== undefined) this.phone = phone
			this.getarea()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			async getarea() {
				let res = await this.$api.post(global.apiUrls.arealist);
				console.log(res, 'ressssssss')
				if (res.data.code != 1) {
					this.$message.info(res.data.msg)
					return
				}
				this.areaList = res.data.data
				console.log(this.areaList, 'this.areaList')
			},
			//绑定新手机号
			async bindNewPhoneNumberFunc() {
				if (!validate(this.newPhone, 'require')) {
					this.$message.info('新手机号不能为空');
					return false;
				}
				// if (!validate(this.newPhone, 'phone')) {
				//   this.$message.info('请输入正确的新手机号');
				//   return false;
				// }
				if (!validate(this.smsVerification, 'require')) {
					this.$message.info('短信验证码不能为空');
					return false;
				}
				if (!validate(this.smsVerification, 'captcha')) {
					this.$message.info('请输入正确的短信验证码');
					return false;
				}
				let res = await this.$api.post(global.apiUrls.a6436729929acd, {
					mobile: this.newPhone,
					code: this.smsVerification,
					type: this.type,
					area_code: this.list
				})
				if (res.data.code != 1) {
					this.$message.info(res.data.msg)
					return
				}
				this.$message.info(res.data.msg)
				setTimeout(() => {
					this.logOutFunc()
				}, 800)
			},
			logOutFunc() {
				this.$store.commit('logout')
				uni.reLaunch({
					url: '/pages/tabBar/login/login'
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}

	.inputNewPhone_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.inputNewPhone_fd0_0_c2 {
		width: 32rpx;
		height: 32rpx;
	}

	.inputNewPhone_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.MyInformation_picker5_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}

	.MyInformation_picker5_0_c2 {
		color: #4781f5;
	}

	.inputNewPhone_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.inputNewPhone_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.inputNewPhone_flex_1 {
		background: #fff;
		font-size: 32rpx;
		background-size: 100% auto !important;
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.inputNewPhone_fd1_2 {
		background: var(--benbenbgColor2);
		border-radius: 100rpx 100rpx 100rpx 100rpx;
		font-size: 32rpx;
		color: #fff;
		height: 88rpx;
		line-height: 88rpx;
		width: 686rpx;
		font-weight: 400;
		margin: 80rpx 0rpx 0rpx 0rpx;
	}

	.inputNewPhone_fd1_1_c2 {
		font-size: 32rpx;
		font-weight: 400;
		color: var(--benbenFontColor4);
	}

	.inputNewPhone_fd1_1_c1 {
		line-height: 45rpx;
		color: #333;
		font-size: 32rpx;
		font-weight: 400;
	}

	.inputNewPhone_fd1_0_c1 {
		line-height: 45rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
	}

	.inputNewPhone_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		font-style: normal;
		color: #333;
		width: 182rpx;
	}

	.inputNewPhone_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}
</style>